require('../css/register.less');
const CaptchaMini=require("../lib/captcha-mini.js")
/*不传值，统一走默认值*/

document.ready(function(){
    console.log('你好')
    let captcha1 = new CaptchaMini({
        // lineNum: 6,       //线条数量
        dotR: 2,          //点的半径
        dotNum: 5,       //点的数量
    });



    let code="";
    captcha1.draw(document.querySelector('#captcha'), r => {
       code=r;
        console.log(r);
        
    });  
  
   
    //这是表单验证区域
    let phonetel=document.querySelector("#phonetel");
    let verification=document.querySelector("#verification");
    let verification2=document.querySelector(".verification2");
    let pass1=document.querySelector("#pass1");
    let pass2=document.querySelector("#pass2");
    let registerdate=document.querySelector("#registerdate")
    let datadisplay =document.querySelector("#datadisplay");
   
    registerdate.addEventListener("click",function(){
        let phone=phonetel.value;
        let verif=verification.value; //这是验证码区域
        let pas1=pass1.value;
        let pas2=pass2.value;
    //    let res=/^[a-zA-Z]\w{5,17}$/.test(pas1);
    //    console.log(res);
       
        
        // let verif2=verification2.innerHTML; 
        //  console.log(phone,verif, pas1,pas2,verif2);
         if(!$$.phonefn(phone)){
            datadisplay.textContent="你的手机号码错误";
            
         }else if(verif.toLowerCase()!=code.toLowerCase()){
            datadisplay.textContent="验证码输入有误"
         }else  if(!$$.pasfn1(pas1)){
           
            
           datadisplay.textContent="以字母开头，长度在6~18之间，"
        }else if(pas2!=pas1){
            datadisplay.textContent="两次密码不一致"
        }else{

            axios.post(' http://139.9.177.51:8099/users/add',
                 {
                    "account":phone,
                    "password":pas2,
                 }
            ).then(function(res){
                let ret=res.data;
                console.log(res);
                
                
                if(ret.status===0){
                    setTimeout(function(){
                        location.href="./login.html"
                    },3000)
                    window.$$.showmask('correct-1-mini','注册成功')
                    
                }else if(ret.status===1){
                    window.$$.showmask('cuo','账号已存在')
                }
            }).catch(function(error){
                console.log(error);
                
            })
        }
        window.onkeydown=function(e){
          if(e.keyCode===13){
          axios.post(' http://139.9.177.51:8099/users/add',
            {
               "account":phone,
               "password":pas2,
            }
       ).then(function(res){
           let ret=res.data;
           
           
           if(ret.status===0){
               location.href="./login.html"
           }
       }).catch(function(error){
           console.log(error);
           
       })

    }
}
     
    });
    // 这是键盘抬起时间区域
     //这是键盘抬起时间区域
     window.onkeydown=function(e){
           
            
        if(e.keyCode===13){
         axios.post(' http://139.9.177.51:8099/users/add',
          {
             "account": phonetel.value,
             "password":pass2.value,
          }
     ).then(function(res){
         let ret=res.data;
        
          
         
         if(ret.status===0){
             location.href="./login.html"
         }else if(ret.status===1){
           alert(`你输入的账号已经存在,请重新输入`)
         }
     }).catch(function(error){
         console.log(error);
         
     })





        }
      }

    
})
